package exams.concurrent;

public class SingletonExample {

    private static SingletonExample instance = null;

    public static void main(String[] args) throws InterruptedException {
        for(int i=0; i <100000; i++) {
            (new Thread(new Runnable() {
                @Override
                public void run() {
                    SingletonExample singletonExample = SingletonExample.getInstance();
                    if(singletonExample == null) {
                        System.out.println("singletonExample is null");
                    }
                   // System.out.println(singletonExample);
                }
            })).start();
        }

        Thread.sleep(1000);
    }

    public static SingletonExample getInstance() {
        if(instance == null) {
            synchronized (SingletonExample.class) {
                if(instance == null) {
                    instance = new SingletonExample();
                }
            }
        }
        return instance;
    }


}
